<?php

namespace app\admin\model;

use think\Model;


class Circle extends Model
{

    

    

    // 表名
    protected $name = 'user_circle';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'index_top_time_text',
        'index_top_endtime_text',
        'cate_top_time_text',
        'cate_top_endtime_text',
        'issale_text',
        'authen_text',
        'isshow_text',
        'isshow_pt_text',
        'pt_time_text',
        'add_time_text'
    ];
    

    
    public function getIssaleList()
    {
        return ['1' => __('Issale 1'), '2' => __('Issale 2')];
    }

    public function getAuthenList()
    {
        return ['1' => __('Authen 1'), '2' => __('Authen 2'), '3' => __('Authen 3')];
    }

    public function getIsshowList()
    {
        return ['1' => __('Isshow 1'), '2' => __('Isshow 2')];
    }

    public function getIsshowPtList()
    {
        return ['1' => __('Isshow_pt 1'), '2' => __('Isshow_pt 2')];
    }


    public function getIndexTopTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['index_top_time']) ? $data['index_top_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getIndexTopEndtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['index_top_endtime']) ? $data['index_top_endtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCateTopTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cate_top_time']) ? $data['cate_top_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCateTopEndtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cate_top_endtime']) ? $data['cate_top_endtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getIssaleTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['issale']) ? $data['issale'] : '');
        $list = $this->getIssaleList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAuthenTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['authen']) ? $data['authen'] : '');
        $list = $this->getAuthenList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsshowTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['isshow']) ? $data['isshow'] : '');
        $list = $this->getIsshowList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsshowPtTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['isshow_pt']) ? $data['isshow_pt'] : '');
        $list = $this->getIsshowPtList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPtTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pt_time']) ? $data['pt_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getAddTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['add_time']) ? $data['add_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setIndexTopTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setIndexTopEndtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCateTopTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCateTopEndtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPtTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setAddTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'user_id', [], 'LEFT')->setEagerlyType(0);
    }


    public function vehicle()
    {
        return $this->belongsTo('Vehicle', 'vehicle_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function carcategory()
    {
        return $this->belongsTo('Carcategory', 'cate_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function province()
    {
        return $this->belongsTo('Area', 'province_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function city()
    {
        return $this->belongsTo('Area', 'city_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function area()
    {
        return $this->belongsTo('Area', 'area_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
